package enumtext;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Text {
    public static void main(String[] args) {
        try {
            Class<?> c = Class.forName("enumtext.TextEnum");

            //注意传入对应的参数,获得对应的构造方法来构造对象,当前枚举类是提供了两个参数分别是String和int。
            //后两个为子类参数，大家可以将当前枚举类的key类型改为double验证
            Constructor constructor = c.getDeclaredConstructor
                    (String.class,int.class,int.class,String.class);

            //设置为true后可修改访问权限
            constructor.setAccessible(true);

            TextEnum textEnum = (TextEnum) constructor.newInstance("fffff",111,10,"while");

            System.out.println(textEnum);

        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
}
//枚举不能在类外实例对象
